import unittest

import requests

class TestIhrmEmployeeApi(unittest.TestCase):
    def test01_add(self):
        url = "http://ihrm2-test.itheima.net/api/sys/user"
        headers = {"Content-Type":"application/json",
                   "Authorization":"Bearer 2c697956-432a-453e-9dbb-ae9d0b854ce8"}
        json_data = {
            "username": "猪八戒",
            "mobile": "17289432002",
            "workNumber": "9527",

        }
        resp = requests.post(url=url, headers=headers, json=json_data)
        print(resp.json())
        # 添加断言
        self.assertEqual(200,resp.status_code)
        self.assertEqual(True, resp.json().get("success"))
        self.assertEqual(10000,resp.json().get("code"))
        self.assertIn("操作成功", resp.json().get("message"))


    def test02_query(self):
        url = "http://ihrm2-test.itheima.net/api/sys/user/1557917023537737728"
        headers = {"Content-Type": "application/json",
                   "Authorization": "Bearer 2c697956-432a-453e-9dbb-ae9d0b854ce8"}
        resp = requests.get(url=url, headers=headers)
        print(resp.json())
        # 添加断言
        self.assertEqual(200, resp.status_code)
        self.assertEqual(True, resp.json().get("success"))
        self.assertEqual(10000, resp.json().get("code"))
        self.assertIn("操作成功", resp.json().get("message"))

    def test02_query(self):
        url = "http://ihrm2-test.itheima.net/api/sys/user/1557917023537737728"
        headers = {"Content-Type": "application/json",
                   "Authorization": "Bearer 2c697956-432a-453e-9dbb-ae9d0b854ce8"}
        resp = requests.get(url=url, headers=headers)
        print(resp.json())
        # 添加断言
        self.assertEqual(200, resp.status_code)
        self.assertEqual(True, resp.json().get("success"))
        self.assertEqual(10000, resp.json().get("code"))
        self.assertIn("操作成功", resp.json().get("message"))

